/*
 * bama.cpp
 *
 *  Created on: 2011-5-1
 *      Author: aeolus
 */
#ifndef TEIGHT_H
#define TEIGHT_H
#include <string.h>

#define Num 9 // 棋盘格子大小
#define DirNum 4//可移动的方向

#define RIGHT 0//1
#define UP 1//-3 //在一维数组中，要表示0向上移，即使0的下标－3
#define LEFT 2//-1
#define DOWN 3//3//在一维数组中，要表示0向下移，即使0的下标＋3


//#define X 0
//#define Y 1
using namespace std;

class TEight
{
private :
	int lastSpace;//前一状态的空格位置
	int space;//空格位置

	static int dir[];//移动方向
	static int total;//步数
protected:
	int last ;
	bool hasExpand;
	static int target[Num+1];//目标
	int origin[Num+1];
public :
	virtual void search()=0;
	int getSpace()
	{
		return space;
	}
	int getLastSpace()
	{
		return lastSpace;
	}

	TEight(int *_orgin , int *_target)
	{
		memcpy(origin,_orgin,sizeof(int)*(Num+1));
		memcpy(target,_target,sizeof(int)*(Num+1));
		last = -1;
		for(int i=1;i<=Num; i++)
		{
			if(origin[i]==0)
			{
				space = i;
				break;
			}
		}
		total = 0;
		hasExpand = false;
	}
	TEight()
	{
		last = -1;
		hasExpand = false;
	}
	void setSpace(int _space)
	{
		space = _space;
	}
	bool isFind();//是还否结束
	void printSelf();
	bool operator == (const TEight &teight);
	bool extend(int direction);//若在方向direction可扩展，则扩展并返回true；否则返回false
};

#endif
